<template>
  <div class="a">
    <el-row type="flex" class="row-bg" justify="center">
      <el-form :model="loginForm" :rules="rules" ref="loginForm" label-width="110px" class="loginForm">
        <!-- <div class="form"> -->
        <h2 class="h2">核酸采样管理系统</h2>
        <el-form-item label="用户名" prop="username" style="width: 350px;">
          <el-input v-model="loginForm.username" placeholder="用户名"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password" style="width: 350px;">
          <el-input v-model="loginForm.password" type="password" placeholder="密码"></el-input>
        </el-form-item>
        <el-form-item label="验证码" prop="code">
          <el-input v-model="loginForm.code" style="width: 110px; float: left" placeholder="验证码"></el-input>
          <el-image :src="captchaImg" class="captchaImg" @click="getCaptcha"></el-image>
        </el-form-item>

        <el-form-item class="button1">
          <el-button type="primary" @click="submitForm('loginForm')" style="margin-right:20px">立即创建</el-button>
          <el-button @click="resetForm('loginForm')">重 置</el-button>
        </el-form-item>
        <!-- </div> -->
      </el-form>
    </el-row>
  </div>
</template>

<script>
import qs from 'qs';
export default {
  name: "Login",
  data() {
    return {
      loginForm: {
        username: 'system',
        password: '12345678',
        code: '',
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
        code: [
          { required: true, message: "请输入验证码", trigger: "blur" },
          { min: 5, max: 5, message: "长度在 5 个字符", trigger: "blur" },
        ],
      },
      captchaImg: this.$baseUrl + '/captcha?time' + new Date(),
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // this.$axios.post('/loginAdmin?username=' + this.loginForm.username + '&password='
          //   + this.loginForm.password + '&code=' + this.loginForm.code, this.loginForm).then(res => {
          //     const token = res.data.data.token
          //     console.log('token:' + token)
          //     this.$store.commit('SET_TOKEN', token)
          //     this.$router.push("/index")
          //   })
          this.$axios.post('/loginAdmin?' + qs.stringify(this.loginForm)).then(res => {
            const token = res.data.data.token
            console.log('token:' + token)
            this.$store.commit('SET_TOKEN', token)
            this.$router.push("/index")
          })
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    getCaptcha() {
      this.captchaImg = this.$baseUrl + '/captcha?time' + new Date();
    },

  },

  created() {

  },
  components: {


  },
};
</script>

<style scoped>
/* #app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 0px;
}

body {
  margin: 0;
  padding: 0;
  border: 0
} */

.a {
  background: url("../../static/images/1.png");
  width: 100%;
  height: 100%;
  position: fixed;
  background-size: 100% 100%;
}


.el-row {
  /* position: relative; */
  /* height: 100%; */
  display: flex;
  margin: 270px auto;

}

.el-form {
  width: 400px;
  padding: 5px;
  background-color: rgba(235, 227, 229, 0.8);
  /* background-color: aliceblue; */
  border-radius: 10px;
  /* box-shadow: 0px 0px 6px 5px rgb(128, 125, 125); */
  box-shadow: 0px 0px 6px 5px rgb(183, 183, 232);

}

.captchaImg {
  float: left;
  margin-left: 10px;
  border-radius: 4px;
}

.form {
  /* display: block; */
  margin-right: 30px;

}

.h2 {
  /* display: block; */
  margin: 15px auto;
  text-align: center;
  /* margin-left: 160px; */
}

.button1 {
  display: flex;
  /* margin: 15px auto; */
}
</style>


